package com.hp.attendance.serlvet.oneself;

import com.hp.attendance.entity.Employee;
import com.hp.attendance.service.EmployeeService;
import org.omg.CORBA.DATA_CONVERSION;

import javax.servlet.ServletException;
import javax.servlet.annotation.WebServlet;
import javax.servlet.http.HttpServlet;
import javax.servlet.http.HttpServletRequest;
import javax.servlet.http.HttpServletResponse;
import java.io.IOException;
import java.sql.SQLException;
import java.text.ParseException;
import java.text.SimpleDateFormat;
import java.util.Date;

@WebServlet("/oneselfUpdate")
public class OneselfUpdateServlet extends HttpServlet {
    private EmployeeService employeeService=new EmployeeService();
    @Override
    protected void doGet(HttpServletRequest req, HttpServletResponse resp) throws ServletException, IOException {
        int id = Integer.parseInt(req.getParameter("id"));
        int employeeNumber = Integer.parseInt(req.getParameter("employeeNumber"));
        String name = req.getParameter("name");
        String password = req.getParameter("password");
        String gender = req.getParameter("gender");

        String birthday =  req.getParameter("date");
        Date birthday1 = null;
        try {
            birthday1 = new SimpleDateFormat("yyyy-MM-dd").parse(birthday);
        } catch (ParseException e) {
            e.printStackTrace();
        }
        String telephone = req.getParameter("telephone");
        String email = req.getParameter("email");
        String address = req.getParameter("address");
        String education = req.getParameter("education");
        String notes = req.getParameter("notes");
        Employee employee = new Employee(id,name,gender,birthday1,telephone,email,address,education,password,notes);
        try {
            employeeService.oneselfUpdate(employee);
        } catch (SQLException throwables) {
            throwables.printStackTrace();
        } catch (ClassNotFoundException e) {
            e.printStackTrace();
        }
        req.getRequestDispatcher("/oneselfadd").forward(req,resp);
    }

    @Override
    protected void doPost(HttpServletRequest req, HttpServletResponse resp) throws ServletException, IOException {
        doGet(req, resp);
    }
}
